<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="UTF-8">
  <head>
  <%@include file="/WEB-INF/include-head.jsp" %>
  <link rel="stylesheet" href="ztree/zTreeStyle.css">
  <script type="text/javascript" src="ztree/jquery.ztree.all-3.5.min.js"></script>
  <script type="text/javascript" src="script/menu.js"></script>
  <SCRIPT type="text/javascript">
  //初始菜单，菜单js在menu.js
  $(function(){
	  initMenu();

	//添加提交动作
	  $("#addModalBtn").click(function(){
	  	//获取各个属性值
	  	var name = $.trim($("#menuAddModal [name='name']").val());
	  	var url = $.trim($("#menuAddModal [name='url']").val());
	  	var icon = $("#menuAddModal [name='icon']:checked").val();
	  	//发生ajax
	  	$.ajax({
	  		"url":"menu/add.json",
	  		"type":"post",
	  		"data":{
	  			"name":name,
	  			"url":url,
	  			"icon":icon,
	  			"pid":window.menuid
	  		},
	  		"dataType":"json",
	  		"success":function(req){
	  			var result=req.result;
	  			if(result=="SUCCESS"){
	  				initMenu();
	  			}else{
	  				layer.msg("添加失败:"+req.message);
	  			}
	  			 $("#menuAddModal").modal("hide");//成功失败都关闭模态框
	  		},
	  		"error":function(req){
	  			layer.msg("ajax请求失败!");
	  			$("#menuAddModal").modal("hide");//成功失败都关闭模态框
	  		}
	  	});
	  	
	  });
	
	
	//更新提交动作
	  $("#editModalBtn").click(function(){
	  	//获取各个属性值
	  	var name = $.trim($("#menuEditModal [name='name']").val());
	  	var url = $.trim($("#menuEditModal [name='url']").val());
	  	var icon = $("#menuEditModal [name='icon']:checked").val();
	  	//发生ajax
	  	$.ajax({
	  		"url":"menu/update.json",
	  		"type":"post",
	  		"data":{
	  			"name":name,
	  			"url":url,
	  			"icon":icon,
	  			"pid":window.pid,
	  			"id":window.menuid
	  		},
	  		"dataType":"json",
	  		"success":function(req){
	  			var result=req.result;
	  			if(result=="SUCCESS"){
	  				layer.msg("更新成功");
	  				initMenu();
	  			}else{
	  				layer.msg("更新失败:"+req.message);
	  			}
	  			 $("#menuEditModal").modal("hide");//成功失败都关闭模态框
	  		},
	  		"error":function(req){
	  			layer.msg("ajax请求失败!");
	  			$("#menuEditModal").modal("hide");//成功失败都关闭模态框
	  		}
	  	});
	  	
	  });
	  
  });
  </SCRIPT>
  </head>
  <body>
	<!-- nav -->
	<%@include file="/WEB-INF/include-nav.jsp" %>
    <div class="container-fluid">
      <div class="row">
        <%@include file="/WEB-INF/include-sidebar.jsp" %>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
          	
          	<div class="panel panel-default">
              <div class="panel-heading"><i class="glyphicon glyphicon-th-list"></i> 权限菜单列表 <div style="float:right;cursor:pointer;" data-toggle="modal" data-target="#myModal"><i class="glyphicon glyphicon-question-sign"></i></div></div>
			  <div class="panel-body">
                  <ul id="treeDemo" class="ztree"></ul>
			  </div>
			</div>
          
        </div>
      </div>
    </div>
	
	<!-- 模态框 -->
	<%@include file="/WEB-INF/include-modal-addMenu.jsp" %>
	<%@include file="/WEB-INF/include-modal-editMenu.jsp" %>
  </body>
</html>